package sample.Admin;

import controller.admin.AdminCourseController;
import controller.admin.AdminStuController;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TableView;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

import java.sql.SQLException;
import java.util.Timer;
import java.util.TimerTask;

public class AdminCourse extends Application {
    public void start(Stage primaryStage) throws  Exception{
        try{
            FXMLLoader loader = new FXMLLoader(getClass().getResource("../../fxml/admin/管理员课程管理.fxml"));
            AnchorPane anchorPane = loader.load();
            Stage stage = new Stage();
            Updater updater = new Updater();
            updater.setAdminCourseController(loader.getController());
            updater.setRoot((Parent)anchorPane);
            new Timer().schedule(updater,0,30000);
            Scene sc = new Scene(anchorPane,750,400);
            stage.setScene(sc);
            stage.setResizable(false);
            stage.show();
        }catch (Exception e ){
            e.printStackTrace();
        }
    }

    class Updater extends TimerTask {
        private Parent root;
        private AdminCourseController adminCourseController;

        public Parent getRoot() {
            return root;
        }

        public void setRoot(Parent root) {
            this.root = root;
        }

        public AdminCourseController getAdminCourse() {
            return adminCourseController;
        }

        public void setAdminCourseController(AdminCourseController adminCourse) {
            this.adminCourseController = adminCourse;
        }

        @Override
        public void run() {
            try {
                TableView tableView = (TableView) root.lookup("#adm_tblList_course");
                adminCourseController.update(tableView);
                System.out.println("定时更新!!");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {
        launch(args);
    }
}
